package com.im.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import com.im.service.dto.Staff;
import com.im.util.JsonUtil;
import com.im.util.ReturnsUtil;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/exaController")
public class ExampleController extends BaseController{

  @RequestMapping("/example")
  public String example(){
    return "test";
  }

  /**
   * 仅包含一个对象的（如增，删，改）
   */
  @RequestMapping("/example1")
  @ResponseBody
  public String example1(@RequestParam Staff staff) {

    try {
      System.out.println(JSONObject.fromObject(staff).toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    return ReturnsUtil.returnSuccess("{}").toString();
  }

  /**
   * 仅包含一个对象的（如增，删，改）
   */
  @RequestMapping("/example2")
  @ResponseBody
  public String example2(@RequestBody String jsonstr) {

    try {
      Staff staff = (Staff) JsonUtil.jsonstrToBeanObj(jsonstr,Staff.class);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return ReturnsUtil.returnSuccess("{}").toString();
  }

}
